package cn.tonyandmoney.voicenotes.notes.presenter

import cn.tonyandmoney.baidu.asr.event.AsrResultEvent
import cn.tonyandmoney.baidu.asr.model.AsrFilterInvocation
import cn.tonyandmoney.baidu.bus.SpeechBus
import cn.tonyandmoney.voicenotes.notes.filters.IntentFilter
import io.reactivex.functions.Consumer

class MainActPresenter(private val mainView: IMainView) {

    private val filterInvocation = AsrFilterInvocation()


    init {
        SpeechBus.register(onResultEvent())
        filterInvocation.addFilter(IntentFilter(mainView))
    }

    fun start() {}

    /**
     * 接收
     */
    private fun onResultEvent(): Consumer<AsrResultEvent> {
        return Consumer {
            val nluResult = it.nluResult
            if (it.code == AsrResultEvent.CODE_FINAL && nluResult.hasNluResult()) filterInvocation.doFilter(it.nluResult)
        }
    }

    interface IMainView : IOperation

}